import { z } from "zod";

// const User = z.object({
//   username: z.string(),
// });
const User = z.object({
  username: z.string(),
  age: z.number().optional()
}) //.isOptional();

const res1 = User.parse({ username: "Ludwig" });
// res1 { username: 'Ludwig' }
console.log('res1', res1);
// 报错
const res2 = User.parse({ username: 123 });
console.log('res2', res2);
// extract the inferred type
type User = z.infer<typeof User>;
// { username: string }
